app.get(ꞌ/:nameꞌ)   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 9.4285
1
var express = require('express');
2
var path = require('path');
3
var favicon = require('serve-favicon');
4
var logger = require('morgan');
5
var mysql = require('mysql');
6
var cookieParser = require('cookie-parser');
7
var bodyParser = require('body-parser');
8
var cors = require('cors');
9
var passport = require('passport');
10
var GoogleStrategy = require('passport-google-oauth20').Strategy;
11
var database = require('./routes/database');
12
var routes = require('./routes/index');
13
var api = require('./routes/projects');
14
15
16
var app = express();
17
18
// view engine setup
19
app.set('views', path.join(__dirname, 'views'));
20
app.set('view engine', 'ejs');
21
22
// uncomment after placing your favicon in /public
23
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
24
app.use(logger('dev'));
25
app.use(bodyParser.json());
26
app.use(bodyParser.urlencoded({extended: false}));
27
app.use(cookieParser());
28
app.use(express.static(path.join(__dirname, 'public')));
29
app.use(cors());
30
/*passport.use(new GoogleStrategy({
31
    clientID: 556527221886-1gov53rrlcidvkqjiuuffe8gvet5mqvo.apps.googleusercontent.com,
32
    clientSecret: zTaO8qmwJuVPWw6LdnrSYITF,
33
    callbackURL: "someurl"
34
    },
35
    function(accessToken, refreshToken, profile, cb) {
36
        User.findOrCreate({googleId: profile.id}, function(err, user) {
37
            return cb(err, user);
38
        });
39
    }
40
));*/
41
42
app.use('/', routes);
43
44
45
46
47
48
//Single page application **Must be below all the APIs**
49
app.get('/:name', function (req, res) {
50
    var name = req.params.name;
51
    console.log(name);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
52
    res.render(name);
53
});
54
55
56
57
// catch 404 and forward to error handler
58
app.use(function (req, res, next) {
59
    var err = new Error('Not Found');
60
    err.status = 404;
61
    next(err);
62
});
63
64
// error handlers
65
66
// development error handler
67
// will print stacktrace
68
if (app.get('env') === 'development') {
69
    app.use(function (err, req, res, next) {
0 ignored issues
show
Unused Code introduced by
The parameter next is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
70
        res.status(err.status || 500);
71
        res.render('error', {
72
            message: err.message,
73
            error: err
74
        });
75
    });
76
}
77
78
// production error handler
79
// no stacktraces leaked to user
80
app.use(function (err, req, res, next) {
0 ignored issues
show
Unused Code introduced by
The parameter next is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
81
    res.status(err.status || 500);
82
    res.render('error', {
83
        message: err.message,
84
        error: {}
85
    });
86
});
87
88
89
module.exports = app;
90